package bigbanksystemserver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class MainMenuController {

    private Connection dbConn;
    private Object[] branchList;

    public MainMenuController() {
        generateBranchList();
    }

    private void generateBranchList() {
        List<String> list = new ArrayList<String>();

        try {
            Class.forName("com.mysql.jdbc.Driver");
            dbConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bankdb", "Jay", "12345678");
            PreparedStatement stmtSearch = dbConn.prepareStatement("SELECT * FROM branch");
            ResultSet rsSearch = stmtSearch.executeQuery();

            while (rsSearch.next()) {
                list.add(rsSearch.getString("branchID") + " (" + rsSearch.getString("ipAddress") + ")");
            }

            branchList = list.toArray();
            dbConn.close();
        } catch (Exception ex) {
        }
    }

    public Object[] getBranchList() {
        return branchList;
    }
}
